<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:awc="clr-namespace:Assergs.Windows.Controls"
    xmlns:aw="clr-namespace:Assergs.Windows"
	>

    <SolidColorBrush x:Key="GlyphBrush" Color="{x:Static aw:SliderPallet.Glyph}"/>
    <SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:SliderPallet.NormalBorder}"/>
    <SolidColorBrush x:Key="NormalBackgroundBrush" Color="{x:Static aw:SliderPallet.NormalBackground}"/>
    <SolidColorBrush x:Key="SideButtonsExternalBorderBrush" Color="{x:Static aw:SliderPallet.SideButtonsExternalBorder}"/>
    <SolidColorBrush x:Key="SideButtonsInternalBorderBrush" Color="{x:Static aw:SliderPallet.SideButtonsInternalBorder}"/>

    <LinearGradientBrush x:Key="SideButtonsBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsBackground2}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsBackground3}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsBackground4}" Offset="1"></GradientStop>
    </LinearGradientBrush>
    
    <LinearGradientBrush x:Key="ThumbBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:SliderPallet.ThumbBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.ThumbBackground2}" Offset="0.3"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.ThumbBackground3}" Offset="0.8"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.ThumbBackground4}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="SideButtonsLightBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsLightBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsLightBackground2}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsLightBackground3}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsLightBackground4}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="SideButtonsPlusLightBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsPlusLightBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsPlusLightBackground2}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsPlusLightBackground3}" Offset="0.4"></GradientStop>
        <GradientStop Color="{x:Static aw:SliderPallet.SideButtonsPlusLightBackground4}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <Style x:Key="BaseSliderSidesButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="IsTabStop" Value="True"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="Width" Value="18"/>
        <Setter Property="Height" Value="18"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Ellipse
                            Name="external"
                            Stroke="{StaticResource SideButtonsExternalBorderBrush}"
                            StrokeThickness="1"/>
                        <Ellipse
                            Name="internal"
                            Margin="1"
                            Fill="{StaticResource SideButtonsBackgroundBrush}"
                            Stroke="{StaticResource SideButtonsInternalBorderBrush}"
                            StrokeThickness="1"/>
                        <ContentPresenter
                            Content="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!--<Trigger Property="IsEnabled" Value="True">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource VScrollBarBtnBgMouseOver}" />
                            <Setter TargetName="Border" Property="BorderThickness" Value="1"/>
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ScrollBarNormalBorderBrush}"/>
                        </Trigger>-->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="internal" Property="Fill" Value="{StaticResource SideButtonsLightBackgroundBrush}" />
                        </Trigger>
                        <Trigger Property="RepeatButton.IsPressed" Value="True">
                            <Setter TargetName="internal" Property="Fill" Value="{StaticResource SideButtonsPlusLightBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SliderButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="Transparent"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="HorizontalSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Height" Value="18"/>
        <Setter Property="Width" Value="10"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border
                        Name="border" 
                        CornerRadius="2,2,2,2"
                        BorderThickness="1"
                        Background="{StaticResource ThumbBackgroundBrush}"
                        BorderBrush="{StaticResource NormalBorderBrush}"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{StaticResource SideButtonsLightBackgroundBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{StaticResource SideButtonsPlusLightBackgroundBrush}" />
                        </Trigger>
                        <!--<Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Ellipse" Property="Fill" Value="{StaticResource DisabledBackgroundBrush}"/>
                        </Trigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="VerticalSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Height" Value="10"/>
        <Setter Property="Width" Value="18"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border
                        Name="border" 
                        CornerRadius="2,2,2,2"
                        BorderThickness="1"
                        Background="{StaticResource ThumbBackgroundBrush}"
                        BorderBrush="{StaticResource NormalBorderBrush}"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{StaticResource SideButtonsLightBackgroundBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{StaticResource SideButtonsPlusLightBackgroundBrush}" />
                        </Trigger>
                        <!--<Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Ellipse" Property="Fill" Value="{StaticResource DisabledBackgroundBrush}"/>
                        </Trigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="HorizontalSlider" TargetType="{x:Type Slider}">
                
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="18"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="18"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TickBar
                Name="TopTick"
                SnapsToDevicePixels="True"
                Fill="{StaticResource GlyphBrush}"
                Height="4"
                Grid.Column="1"
                Grid.Row="0"
                Visibility="Collapsed" />

            <Border
                Name="TrackBackground"
                Margin="0"
                CornerRadius="2"
                Height="2"
                Grid.Row="1"
                Grid.Column="1"
                Background="{StaticResource NormalBackgroundBrush}"
                BorderBrush="{StaticResource NormalBorderBrush}"
                BorderThickness="0,1,0,0" />

            <RepeatButton
                Grid.Column="0"
                Grid.Row="1"
                Command="Slider.DecreaseLarge"
                Style="{StaticResource BaseSliderSidesButtonStyle}">

                <Border Width="8" Height="2" Background="{StaticResource GlyphBrush}"></Border>

            </RepeatButton>

            <Track Grid.Column="1" Grid.Row="1" Name="PART_Track">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Style="{StaticResource SliderButtonStyle}" Command="Slider.DecreaseLarge"/>
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Name="HorizontalThumb" Style="{StaticResource HorizontalSliderThumbStyle}"/>
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Style="{StaticResource SliderButtonStyle}" Command="Slider.IncreaseLarge"/>
                </Track.IncreaseRepeatButton>
            </Track>

            <RepeatButton
                Grid.Row="1"
                Grid.Column="2"
                Command="Slider.IncreaseLarge"
                Style="{StaticResource BaseSliderSidesButtonStyle}">

                <Path Fill="{StaticResource GlyphBrush}" Stretch="None">
                    <Path.Data>
                        <CombinedGeometry GeometryCombineMode="Union">
                            <CombinedGeometry.Geometry1>
                                <RectangleGeometry Rect="3,0,2,8"></RectangleGeometry>
                            </CombinedGeometry.Geometry1>
                            <CombinedGeometry.Geometry2>
                                <RectangleGeometry Rect="0,3,8,2"></RectangleGeometry>
                            </CombinedGeometry.Geometry2>
                        </CombinedGeometry>
                    </Path.Data>
                </Path>

            </RepeatButton>

            <TickBar
                Name="BottomTick"
                SnapsToDevicePixels="True"
                Grid.Column="1"
                Grid.Row="2"
                Fill="{TemplateBinding Foreground}"
                Height="4"
                Visibility="Collapsed"/>

        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="TickPlacement" Value="TopLeft">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="BottomRight">
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="Both">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalSlider" TargetType="{x:Type Slider}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto" MinWidth="{TemplateBinding Slider.MinWidth}"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="18"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="18"/>
            </Grid.RowDefinitions>
            
            <TickBar
              Name="TopTick"
              SnapsToDevicePixels="True"
              Placement="Left"
              Grid.Row="1"
              Grid.Column="2"
              Fill="{StaticResource GlyphBrush}"
              Width="4"
              Visibility="Collapsed" />
            
            <Border
                Name="TrackBackground"
                Margin="0"
                CornerRadius="2"
                Width="2"
                Grid.Row="1"
                Grid.Column="1"
                Background="{StaticResource NormalBackgroundBrush}"
                BorderBrush="{StaticResource NormalBorderBrush}"
                BorderThickness="1,0,0,0" />
            
            <RepeatButton
                Grid.Row="0"
                Grid.Column="1"
                Command="Slider.IncreaseLarge"
                Style="{StaticResource BaseSliderSidesButtonStyle}">

                <Path Fill="{StaticResource GlyphBrush}" Stretch="None">
                    <Path.Data>
                        <CombinedGeometry GeometryCombineMode="Union">
                            <CombinedGeometry.Geometry1>
                                <RectangleGeometry Rect="3,0,2,8"></RectangleGeometry>
                            </CombinedGeometry.Geometry1>
                            <CombinedGeometry.Geometry2>
                                <RectangleGeometry Rect="0,3,8,2"></RectangleGeometry>
                            </CombinedGeometry.Geometry2>
                        </CombinedGeometry>
                    </Path.Data>
                </Path>

            </RepeatButton>
                        
            <Track Grid.Column="1" Grid.Row="1" Name="PART_Track">
                <Track.DecreaseRepeatButton>
                    <RepeatButton
                      Style="{StaticResource SliderButtonStyle}"
                      Command="Slider.DecreaseLarge" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Style="{StaticResource VerticalSliderThumbStyle}"/>
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton
                      Style="{StaticResource SliderButtonStyle}"
                      Command="Slider.IncreaseLarge" />
                </Track.IncreaseRepeatButton>
            </Track>
            
            <TickBar
              Name="BottomTick"
              SnapsToDevicePixels="True"
              Grid.Row="1"
              Grid.Column="0"
              Fill="{TemplateBinding Foreground}"
              Placement="Right"
              Width="4"
              Visibility="Collapsed" />
            
            <RepeatButton
                Grid.Column="1"
                Grid.Row="2"
                Command="Slider.DecreaseLarge"
                Style="{StaticResource BaseSliderSidesButtonStyle}">

                <Border Width="8" Height="2" Background="{StaticResource GlyphBrush}"></Border>

            </RepeatButton>
            
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="TickPlacement" Value="TopLeft">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="BottomRight">
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="TickPlacement" Value="Both">
                <Setter TargetName="TopTick" Property="Visibility" Value="Visible"/>
                <Setter TargetName="BottomTick" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="{x:Type Slider}" TargetType="{x:Type Slider}">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="MinWidth" Value="104" />
                <Setter Property="MinHeight" Value="21" />
                <Setter Property="Template" Value="{StaticResource HorizontalSlider}" />
            </Trigger>
            <Trigger Property="Slider.Orientation" Value="Vertical">
                <Setter Property="MinWidth" Value="21" />
                <Setter Property="MinHeight" Value="104" />
                <Setter Property="Template" Value="{StaticResource VerticalSlider}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>